package com.xw.db137.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xw.db137.common.R;
import com.xw.db137.entity.Rolemenu;
import com.xw.db137.service.RolemenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @Author: xw
 * @CreateTime: 2024/12/24
 * @Description: 用户
 * @Version: 1.0
 */
@RestController
@CrossOrigin(origins = "*")
public class RolemenuController {
    @Autowired
    private RolemenuService rolemenuService;

    /**
     * 根据角色id查询菜单集合
     * @param id
     * @return
     */
    @GetMapping("/selectRoleMenuById/{id}")
    public R selectRoleMenuById(@PathVariable("id") int id) {
        QueryWrapper<Rolemenu> rolemenuQueryWrapper = new QueryWrapper<>();
        rolemenuQueryWrapper.eq("roleid", id);
        List<Rolemenu> rolemenuList = rolemenuService.list(rolemenuQueryWrapper);
        return new R().addData("rolemenuList", rolemenuList);
    }

    /**
     * 根据角色id修改对应的菜单id集合
     * @return
     */
    @PostMapping("/updateRoleMenuId")
    public R updateRoleMenuId(@RequestBody Map<String, Object> map) {
        int roleid = Integer.parseInt(map.get("roleid") + "");//角色id
        List<Integer> listMenu = (List<Integer>) map.get("listMenu");
        boolean bol = this.rolemenuService.updateRoleMenuId(roleid,listMenu);
        System.out.println(roleid + "===" + listMenu);
        return new R();
    }
}
